import 'package:flutter/widgets.dart';
import 'package:imperius_insights/entity/project.dart';
import 'package:imperius_insights/entity/quality.dart';
import 'package:imperius_insights/treaty/dimensions.dart';
import 'package:imperius_insights/treaty/styles.dart';

Widget buildQualityLabel(BuildContext context, Project project) {
  if (project.staging == Staging.Develop ||
      project.staging == Staging.SelfTesting ||
      project.staging == Staging.PendingToTest) {
    return DevQualityLabel(quality: project.qualityInRDTesting);
  }
  if (project.staging == Staging.QATesting ||
      project.staging == Staging.PrePublish ||
      project.staging == Staging.PostPublish) {
    return QAQualityLabel(quality: project.qualityInQATesting);
  }
  return Container();
}

class DevQualityLabel extends StatelessWidget {
  final QualityInRDTesting quality;

  const DevQualityLabel({Key key, this.quality}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final text = quality.caseTotal == 0
        ? '无case记录'
        : '开发自测Case：${quality.caseExecuted}/${quality.caseTotal} (${quality.rdExecutiveRate})';
    return Container(
        padding: EdgeInsets.fromLTRB(
            layoutDimensions.cardPaddingHorizontal,
            layoutDimensions.cardPaddingVertical,
            layoutDimensions.cardPaddingHorizontal,
            layoutDimensions.cardPaddingVertical),
        child: Text(text, style: styles.contentTip));
  }
}

class QAQualityLabel extends StatelessWidget {
  final QualityInQATesting quality;

  const QAQualityLabel({Key key, this.quality}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final text = quality.caseTotal == 0
        ? '无case记录'
        : 'QA执行：${quality.notRdExecutiveCount}/${quality.caseTotal} (${quality.notRdExecutiveRate})\n'
            'Bug数：${quality.bugTotal} (${quality.bugRate})\n'
            '开发自测：${quality.caseExecuted}/${quality.caseTotal} (${quality.rdExecutiveRate})';
    return Container(
        padding: EdgeInsets.fromLTRB(
            layoutDimensions.cardPaddingHorizontal,
            layoutDimensions.cardPaddingVerticalHalf,
            layoutDimensions.cardPaddingHorizontal,
            layoutDimensions.cardPaddingVertical),
        child: Text(text, style: styles.contentTip));
  }
}
